package com.itheima.controller;

import com.itheima.pojo.*;
import com.itheima.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController

public class EmpController {

    @Autowired
    private EmpService empService;
    // 查询

    @GetMapping("/emps")
    public Result getEmpList(
            EmpQueryParam empQueryParam
            ) {
        PageBean<Emp> data = empService.getEmps(empQueryParam);
        return Result.success(data);
    }

    // 新增

    @PostMapping("/emps")
    public Result save(@RequestBody Emp emp) {

        empService.save(emp);

        return Result.success();
    }

    //     删除
    @DeleteMapping("/emps")
    public Result delBatchEmp(@RequestParam List<Integer> ids) {
        System.out.println("ids = " + ids);
        empService.delBatchEmp(ids);

        return Result.success();

    }

    //     回显的接口
    @GetMapping("/emps/{id}")
    public Result selectEmpById(@PathVariable Integer id) {
        Emp emp = empService.selectEmpById(id);
        return Result.success(emp);
    }

//     修改员工的问题：


    @PutMapping("/emps")
    public Result updateEmpInfo(@RequestBody Emp emp) {
        empService.updateEmpInfo(emp);
        return Result.success();
    }

   // 查询所有员工的接口
    @GetMapping("/emps/list")
     public Result getAllEmps(){
      List<Emp> empList =  empService.getAllEmps();
        return Result.success(empList);
     }
}
